define(["app","js/signature/formListView","js/init", 'js/utils','js/util/toast','js/util/socketUtil'], 
	function(app, formView,base,Utils,toast,initSocket) {
	
		
	var _defautl = {
		page	: 0 ,
		rows	: 10
	}
	var curConfig = {
		//当前业务模块
		code	: null ,
		//当前业务模块名称
		name	: null ,
		//当前记录id
		id		: null,
		//当前页
		page	: 0 ,
		//当前行
		rows	: 10
	}
	var bindings = [		
		//导航链接
		{
			element: '#formList-page .back-link',
			event: 'click',
			handler: clickBack
		}
		,
		//导航链接
		{
			element: '#formList-page .new-link',
			event: 'click',
			handler: clickNew
		}
	];
	
	/**
	 * 回退按钮事件
	 */
	function clickBack(){
		if(!app.mainView){
			app = app.getApp();
		}
		
		var _cv = app.f7.getCurrentView();

		if(_cv && _cv.router){
			_cv.router.load({pageName:'signature/type'});
		}
	}
	
	/**
	 * 新增按钮事件
	 */
	function clickNew(){
		if(!app.mainView){
			app = app.getApp();
		}
		
		var _cv = app.f7.getCurrentView();
		
		if(_cv && _cv.router){
			app.f7.showPreloader('loading...');
			_cv.router.load({url:'app/signature/form.html',query:{code:curConfig.code,name:curConfig.name,id:curConfig.id}});
		}
	}
	
	function init(query){	
		
		if(!app.mainView){
			app = app.getApp();
		}
		
		if(query.name){
			$('#formList-page .biz-title').html(query.name);
		}
		
		curConfig = $.extend({},_defautl);
		
		var data
		if(query.code){			
			curConfig.code = query.code;	
			curConfig.name = query.name;
			refresh(query.code)
		}else{
			app.f7.hidePreloader();
		}
	}
	
	/**
	 * 刷新数据
	 */
	function refresh(code){
		
		var _code = curConfig.code;
		if(code){
			_code = code;
		}
		
		if(!app.mainView){
			app = app.getApp();
		}
		var _d = {
			userid	: (app.getUser()).userid,
			page	: curConfig.page,
			rows	: curConfig.rows,
			bizcode	: curConfig.code
		}
		
		
		$.ajax({
			url : base.base + '/oa/oaGeneral/query/getUserManagedTaskDomain.action',
			data: JSON.stringify(_d),
			dataType: 'json',
			type	: 'post',
			contentType: 'appliction/json;charset=utf-8',
			success:function(data){
				var _m
				if(data && data.rows){
					_m = data.rows
				}
				formView.render({
					model	: _m ,
					bindings: bindings
				});
				app.f7.hidePreloader();
			}
			,
			error:function(){
				toast.show({msg:'获取数据失败！'})
				formView.render({
					model	: null,
					bindings: bindings
				});
				
				app.f7.hidePreloader();
			}
		}) 		
	}
	

	return {
		init: init
	};
});